/*************************************************************************
    > File Name: test4.c
    > Author: H.M. Lau
    > Mail: hm.lau@outlook.com
    > Created Time: 2023/08/30 14:32
 ************************************************************************/

#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>

int main() {
    close(1);
    int fd = open("log.txt", O_WRONLY | O_CREAT | O_TRUNC, 0666);
    if (fd < 0) {
        perror("open");
        return 1;
    }
    printf("fd:%d\n", fd);
    printf("aaaaa\n");
    printf("bbbbb\n");
    fprintf(stdout, "hello fprintf\n");
    const char *s = "hello fwrite\n";
    fwrite(s, strlen(s), 1, stdout);
    /*fflush(stdout);*/
    close(fd);
    return 0;
}
